<?php

namespace Applications\Tool;

use function _\capitalize;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Protobuf
 *
 * @author zy
 */
class Protobuf {

    /**
     * 创建返回消息
     * @param type $name
     * @param type $object
     * @return type
     */
    public static function createRsp($name, $object) {
        $setname = 'set' . capitalize($name);
        $rsd = new \Pb\App\ResponseData();
        $rsd->$setname($object);
        $rsp = (new \Pb\App\MessageResponse())->setMessageData($rsd);
        $rsp->setReqUnique(uniqid());
        $rsp->setTimestamp(get_microtime());
        return $rsp;
    }
    
    public static function obj2array(\Google\Protobuf\Internal\Message $object){
        return json_decode($object->serializeToJsonString(),true);
    }

}
